package com.atguigu.jxc.controller;


import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Customer;
import com.atguigu.jxc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class CustomerController {


    @Autowired
    CustomerService customerService;

    /**
     * 请求URL：http://localhost:8080 /customer/list
     * 请求参数：Integer page, Integer rows, String  customerName
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：Map<String,Object>
     */
    @PostMapping("/customer/list")
    public Map<String,Object> listCustomer(Integer page, Integer rows, String customerName){

        return customerService.list(page,  rows,  customerName);

    }

    /**
     * 请求URL：http://localhost:8080/ customer/save?customerId=1
     * 请求参数：Customer customer
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：ServiceVO
     */
    @PostMapping("customer/save")
    public ServiceVO addSupplier(Customer customer, @RequestParam(value = "customerId",required = false) Integer customerId){

        customerService.addSupplier(customer,customerId);

        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS,null);
    }

    /**
     * 请求URL：http://localhost:8080/customer/delete
     * 请求参数：String  ids
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：ServiceVO
     */
    @PostMapping("/customer/delete")
    public ServiceVO deleteCustomer(String ids){

        customerService.deleteCustomer(ids);

        return new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS,null);



    }


}
